%% Estimate nu by MLE based on MDD

function nu_est = MLE_nu(hat_theta, rep_base_se2, init_guess, max_iter, tol)
% INPUT: baseline study data hat_theta and rep_base_se2, initial guess for nu,
% maximum iterations and tolerence for nonlinear solver
% OUTPUT: EB estimate for nu
    
    % Initialize the optimization
    options = optimoptions('fsolve', 'Display', 'off', 'TolFun', tol, 'MaxIterations', max_iter);
    
    % Use fzero to find nu
    nu_est = fsolve(@(nu) foc(nu, hat_theta, rep_base_se2), init_guess, options);

    % Force hat-nu to be non-negative
    nu_est = max(nu_est, 0);

end